<template>
  <div class="home">
    <c-navigation>
      <c-time @change="timeChangeHandler" downloadBtn/>
    </c-navigation>
    <c-tab :tabList="tabList" :selectKey.sync="selectKey">
      <c-tab-pane>
        <num-card v-for="item in DRGNumData"
                  :key="item.key"
                  :title="item.title"
                  :value="item.value"
                  :unit="item.unit"/>
      </c-tab-pane>
      <c-tab-pane>
        <num-card v-for="(item,index) in efficiencyData"
                  :key="index"
                  :title="item.title"
                  :value="item.value"
                  :unit="item.unit"/>
      </c-tab-pane>
    </c-tab>
    <DRGPage v-if="selectKey==='a'" :timeParams="timeParams"/>
    <efficiency-page v-if="selectKey==='b'" :timeParams="timeParams"/>
  </div>
</template>

<script>
import CTab from "@/components/cTab.vue";
import cTabPane from "@/components/cTabPane.vue";
import numCard from "./components/numCard.vue";
import DRGPage from "./components/subPage/DRGPage";
import efficiencyPage from "./components/subPage/efficiencyPage";
import cardWrapper from "@/components/cardWrapper";
import moment from "moment";
import {dataReport, hospitalPerformanceReport} from "@/api/drgsGroupResults";
import {formatNumber} from "@/utils/transform";

export default {
  name: 'home',
  components: {DRGPage, CTab, cTabPane, numCard, cardWrapper, efficiencyPage},
  data() {
    return {
      tabList: [
        {name: "DIP数据分析", key: 'a'},
        {name: "全院效能数据分析", key: 'b'}
      ],
      selectKey: "a",
      DRGNumData: [
        {value: "", key: "allpoints", title: "总点数金额", unit: '万'},
        {value: "", key: "allCounts", title: "DIP病例数", unit: '例'},
        {value: "", key: "diseaseGroupCounts", title: "DIP病组数", unit: '组'},
        {value: "", key: "againInCounts", title: "15天再入院人次", unit: '人'},
      ],
      efficiencyData: [
        {value: "", key: "avemoney", title: "住院总费用", unit: '万元'},
        {value: "", key: "OutCount", title: "住院人次", unit: '人'},
        {value: "", key: "allmoney", title: "次均费用", unit: '元'},
        {value: "", key: "avedrug_money", title: "次均药品费", unit: '元'},
        {value: "", key: "avematerial_money", title: "次均材料费", unit: '元'},
        {value: "", key: "agedays", title: "平均住院日", unit: '天'},
      ],
      timeParams: {
        year: moment().format('YYYY'),
        month: moment().format('MM')
      }
    }
  },
  created() {
    this.reData();
  },
  methods: {
    reData() {
      this.getDataReport();
      this.getHospitalPerformanceReport();
    },
    timeChangeHandler(e) {
      this.timeParams = e;
      this.reData();
    },
    async getDataReport() {
      const params = {
        ...this.timeParams
      };
      const res = await dataReport(params);
      for (const item of this.DRGNumData) {
        item.value = formatNumber(res['data'][item.key]);
      }
    },
    async getHospitalPerformanceReport() {
      const params = {
        ...this.timeParams
      };
      const res = await hospitalPerformanceReport(params);
      for (const item of this.efficiencyData) {
        item.value = formatNumber(res['data'][item.key]);
      }
    }
  }
}
</script>

<style lang="stylus" scoped>
.c-tab-pane {
  display flex
  justify-content space-around
}
</style>
